import "./index.css";
import Title from "antd/es/typography/Title";
import {
  listQuestionVoByPageUsingPost,
  searchQuestionVoByPageUsingPost,
} from "@/api/questionController";
import { message } from "antd";
import QuestionTable from "@/components/QuestionTable";

// 本页面使用服务端渲染，禁用静态生成
export const dynamic = "force-dynamic";

export default async function Questions({ searchParams }) {
  // 获取url的查询参数
  const { searchText } = searchParams;

  let questionList = []; // 分页查询到的题目数组
  let total = 0; // 总记录数

  if (searchText == null) {
    // 获取题目列表
    const res = await listQuestionVoByPageUsingPost({
      pageSize: 20,
      sortField: "createTime",
      sortOrder: "desc",
    });
    questionList = res?.data?.records || [];
    total = res?.data.total || 0;
  }

  return (
    <div id={"questions"} className={"limit-width"}>
      <Title level={3}>题目大全</Title>
      <QuestionTable
        defaultQuestionList={questionList}
        defaultTotal={total}
        defaultSearchParams={{ searchText }}
      />
    </div>
  );
}
